<template>
  <div>
    <t-space direction="vertical">

      <t-radio-group :default-value="goldAmount" @change="change">
        <t-radio-button :value="10000">10000金币</t-radio-button>
        <t-radio-button :value="30000">30000金币</t-radio-button>
        <t-radio-button :value="50000">50000金币</t-radio-button>
        <t-radio-button :value="100000">100000金币</t-radio-button>

      </t-radio-group>
      <div>10000金币可兑换{{goldAmount/10000}}元</div>

      <t-space direction="horizontal" style="align-items: center;">
        <t-button @click="withdraw">申请提现</t-button>
        <t-link @click="changeAccount"> 绑定支付宝帐号</t-link>
      </t-space>



    </t-space>

    <t-dialog v-model:visible="visible" header="绑定支付宝帐号" :footer="null">
      <account @onBindSuccess="onBindSuccess"></account>
    </t-dialog>
  </div>
</template>

<script setup>
  import {
    ref,defineEmits
  } from 'vue'
  import {
    MessagePlugin
  } from 'tdesign-vue-next'
  import {
    applyWithdraw
  } from '@/api/user'
  import account from './account.vue'
  import {
    useUserStore
  } from '@/store'

const emits=defineEmits(['withdrawApplySuccess'])
  const userStore = useUserStore()
  const visible = ref(false)
  const goldAmount = ref(10000)

//更换提现帐号
const changeAccount=()=>{
  visible.value = true
}
  //提现额度变更
  const change=(e)=>{
    console.log('e=',JSON.stringify(e))
    goldAmount.value=e
  }
  //提现申请
  const withdraw = () => {
    console.log('userStore.assetInfo',JSON.stringify(userStore.assetInfo))
    if (userStore.assetInfo.AlipayWithdrawNo === '') {
      visible.value = true
    } else {
      applyWithdraw({
          amount: goldAmount.value
        })
        .then(ret => {
          userStore.getAssetInfo()
          MessagePlugin.success('己申请提现')

          emits('withdrawApplySuccess')
        })
        .catch(e => {
          MessagePlugin.error(e.msg)
        })
    }

  }

  //绑定帐号成功
  const onBindSuccess = () => {
    visible.value = false
    userStore.getAssetInfo()
  }
</script>


<style>
</style>
